﻿
using System.Collections.Generic;
using Silvermoon.Shapes;
using System.Drawing;
using Silvermoon.Interfaces;
using Silvermoon.OpenGL;
using Silvermoon.Controls.Base;
using Silvermoon.UI;
using System.Diagnostics;
using Silvermoon.Windows;
using System;

namespace Silvermoon.Controls.Beta
{
    [Obsolete("Consider to replace ListBox with new ListView control.")]
    public class ListBoxItem : ItemBase, IColor
    {
        #region fields

        protected StringShape label;

        #endregion
        #region ctor
        public ListBoxItem()
            : base()
        {
            label = new StringShape { Alignment = Alignment.Center, LineAlignment = Alignment.Center };
            Shapes.AddLast(label);
        }

        public ListBoxItem(string text)
            :this()
        {
            Text = text;
        }

        public ListBoxItem(string text, ICommand command)
            : this(text)
        {
            this.Command = command;
        }

        protected override void Dispose(bool dispose)
        {
            base.Dispose(dispose);
        }


        #endregion
        #region props

        public Alignment Alignment
        {
            get { return label.Alignment; }
            set { label.Alignment = value; }
        }

        public Alignment LineAlignment
        {
            get { return label.LineAlignment; }
            set { label.LineAlignment = value; }
        }


        public string Text
        {
            get { return label.Text; }
            set
            {
                if (label.Text != value)
                {
                    label.Text = value;
                    Invalidate(InvalidationFlag.Text);
                }
            }
        }

        public FontSprite Font
        {
            get { return label.Font; }
            set { label.Font = value; }
        }

        #endregion
        #region methods

        protected override void OnLayout()
        {
            if (CheckFlag(InvalidationFlag.Size))
            {
                label.Bounds = Control.ScaledRect(10, 4, Width - 20, Height - 8);
            }
            base.OnLayout();
        }

        Color IColor.Color
        {
            get
            {
                return TextColor;
            }
            set
            {
                TextColor = value;
            }
        }


        public override void SetAnimationState(ItemAnimationType animationType, int progress, int maxProgress, ref Rectangle bounds)
        {
            base.SetAnimationState(animationType, progress, maxProgress, ref bounds);
            switch (animationType)
            {
                case ItemAnimationType.Insert:
                case ItemAnimationType.Remove:
                    if (animationType == ItemAnimationType.Insert) progress = maxProgress - progress;
                    if (progress > 0)
                    {
                        bounds.X -= Screen.Width * progress / maxProgress;

                    }
                    break;
            }
        }

        #endregion
    }

    public class SmallItem : ListBoxItem
    {
        public override void SetAnimationState(ItemAnimationType animationType, int progress, int maxProgress, ref Rectangle bounds)
        {
            switch (animationType)
            {
                case ItemAnimationType.Insert:
                    Opacity = 255 * progress / maxProgress;
                    break;
                case ItemAnimationType.Remove:
                    Opacity = 255 * (maxProgress - progress) / maxProgress;
                    break;
                case ItemAnimationType.None:
                    Opacity = 255;
                    break;
            }
        }
    }
}
